package com.cardbaobao.cardbabyclient.utils;
import android.view.Gravity;
import android.widget.Toast;

/**
 * 吐司弹出提示工具
 * Created by zad
 * 2016/7/27 10:26
 */

public class ToastUtil {

    /**
     Toast统一管理，默认显示位置com.android.internal.R.integer.config_toastDefaultGravity
     指向的值Default Gravity setting for the system Toast view.
     Equivalent to: Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM
     **/
    private static Toast sToast;

    /**
     * 显示toast在系统toast默认位置[横向居中|底部]，toast展示的时间较短
     */
    public static void showToast(CharSequence content){
//        if(sToast==null){
//            sToast=Toast.makeText(ApplicationHelper.getApplicationContext(),
//                    content,
//                    Toast.LENGTH_SHORT);
//        }
//        sToast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM,0,0);
//        sToast.setText(content);
//        sToast.show();
        showToastOnScreenCenter(content);
    }

    /**
     * 显示toast在系统toast默认位置[横向居中|底部]，toast展示的时间较长
     */
    public static void showToastLong(CharSequence content){
//        if(sToast==null){
//            sToast=Toast.makeText(ApplicationHelper.getApplicationContext(),
//                    content,
//                    Toast.LENGTH_LONG);
//        }
//        sToast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM,0,0);
//        sToast.setText(content);
//        sToast.show();
        showToastLongOnScreenCenter(content);
    }

    /**
     * 显示toast到屏幕中间，toast展示时间较短
     */
    public static void showToastOnScreenCenter(CharSequence content){
        if(sToast==null){
            sToast=Toast.makeText(ApplicationHelper.getApplicationContext(),
                    content,
                    Toast.LENGTH_SHORT);
        }
        sToast.setGravity(Gravity.CENTER,0,0);
        sToast.setText(content);
        sToast.show();
    }

    /**
     * 显示toast到屏幕最中间，toast展示时间较长
     */
    public static void showToastLongOnScreenCenter(CharSequence content){
        if(sToast==null){
            sToast=Toast.makeText(ApplicationHelper.getApplicationContext(),
                    content,
                    Toast.LENGTH_LONG);
        }
        sToast.setGravity(Gravity.CENTER,0,0);
        sToast.setText(content);
        sToast.show();
    }

    /**
     * 取消toast显示
     */
    public static void cancelToast(){
        if(sToast!=null){
            sToast.cancel();
        }
    }
}
